//
//  PCenterController.swift
//  flowerpot
//
//  Created by fyname on 15/9/18.
//  Copyright © 2015年 senhe. All rights reserved.
//

import UIKit

class PCenterController: UIViewController {
    
    @IBOutlet weak var avatarImage: UIButton!
    
    let imageName:String = "currentImage.png"

    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 自定义返回按钮
        let backButton = UIBarButtonItem(title: "く返回", style: UIBarButtonItemStyle.Plain, target: self, action: "goBack")
        self.navigationItem.leftBarButtonItem = backButton
        
        // 获取沙盒目录,这里将图片放在沙盒的documents文件夹中
        let home = NSHomeDirectory() as NSString;
        let docPath = home.stringByAppendingPathComponent("Documents") as NSString;
        let fullPath = docPath.stringByAppendingPathComponent(imageName);
        
//        let path = NSBundle.mainBundle().pathForResource("apple", ofType: "png")
        if(!fullPath.isEmpty){
            log.debug("用户有头像!")
            let newImage = UIImage(contentsOfFile: fullPath)
            self.avatarImage.setImage(newImage,forState:.Normal)  //设置图标
            //self.avatarImage.backgroundColor = UIColor(patternImage: newImage!)
        }else{
            log.debug("初始用户没有头像!")
        }
        
        
        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    func goBack() {
        //        self.navigationController?.popViewControllerAnimated(true)
        //        Common.rootViewController.mainTabBarController.tabBar.hidden = false
        print("index")
        Common.rootViewController.mainTabBarController.view.addSubview(Common.indexVC.view)
        Common.rootViewController.mainTabBarController.view.bringSubviewToFront(Common.rootViewController.mainTabBarController.tabBar)
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
